package com.z.base;

import java.io.File;
import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;
import com.z.config.ConfigReader;

public class DbBase {
	private static DbBase dbBase;
	public static DbBase getInstace(){
		if(dbBase==null){
			dbBase=new DbBase();
		}
		return dbBase;
	}
	
	public static final String DB_FILE_NAME="db.dat";
	
	public static String db_path;
	
	private static ObjectContainer objectContainer;
	
	public ObjectContainer getDB(){
		if(objectContainer==null){
			if(db_path==null){
				db_path=ConfigReader.getInstance().getDbPath();
				File file=new File(db_path);
				if(!file.exists()){
					System.out.println(file.mkdirs());
				}
				db_path+=DB_FILE_NAME;
			}
			objectContainer = Db4oEmbedded.openFile(db_path);
		}
		return objectContainer;
	}
}
